package Sequence;

import java.util.Arrays;

public class Test0647 {
}


class Solution0647_1 {
    public int countSubstrings(String s) {
        char[] chars = s.toCharArray();
        int length = chars.length;
        boolean[] dp = new boolean[length+1];
        Arrays.fill(dp, true);

        int ans = 0;
        for (int i = 0; i < length; i++) {
            char c1 = chars[i];
            for (int j = 0; j <= i; j++) {
                char c2 = chars[j];

                if (dp[j+1] && c2 == c1) {
                    ans++;
                    dp[j] = true;
                }else {
                    dp[j] = false;
                }
            }
        }


        return ans;
    }
}